package com.swe.chums.dao.example;

import java.math.*;
import java.util.Date;
import java.util.List;
import com.swe.chums.dao.UserDao;
import com.swe.chums.dao.model.User;
import com.swe.chums.dao.exceptions.UserDaoException;
import com.swe.chums.dao.factory.DaoFactory;

public class UserDaoExample
{
	/**
	 * Method 'main'
	 * 
	 * @param arg
	 * @throws Exception
	 */
	public static void main(String[] arg) throws Exception
	{
		// Uncomment one of the lines below to test the generated code
		
		// findAll();
		// findByUserType(0);
		// findWhereIdEquals(0);
		// findWhereUsernameEquals("");
		// findWhereNameEquals("");
		// findWhereEmailEquals("");
		// findWherePasswordEquals("");
		// findWhereUserTypeIdEquals(0);
	}

	/**
	 * Method 'findAll'
	 * 
	 * @throws Exception
	 */
	public static void findAll() throws Exception
	{
		UserDao dao = DaoFactory.createUserDao();
		List<User> _result = dao.findAll();
		for (User dto : _result) {
			display(dto);
		}
		
	}

	/**
	 * Method 'findByUserType'
	 * 
	 * @param userTypeId
	 * @throws Exception
	 */
	public static void findByUserType(int userTypeId) throws Exception
	{
		UserDao dao = DaoFactory.createUserDao();
		List<User> _result = dao.findByUserType(userTypeId);
		for (User dto : _result) {
			display(dto);
		}
		
	}

	/**
	 * Method 'findWhereIdEquals'
	 * 
	 * @param id
	 * @throws Exception
	 */
	public static void findWhereIdEquals(int id) throws Exception
	{
		UserDao dao = DaoFactory.createUserDao();
		List<User> _result = dao.findWhereIdEquals(id);
		for (User dto : _result) {
			display(dto);
		}
		
	}

	/**
	 * Method 'findWhereUsernameEquals'
	 * 
	 * @param username
	 * @throws Exception
	 */
	public static void findWhereUsernameEquals(String username) throws Exception
	{
		UserDao dao = DaoFactory.createUserDao();
		List<User> _result = dao.findWhereUsernameEquals(username);
		for (User dto : _result) {
			display(dto);
		}
		
	}

	/**
	 * Method 'findWhereNameEquals'
	 * 
	 * @param name
	 * @throws Exception
	 */
	public static void findWhereNameEquals(String name) throws Exception
	{
		UserDao dao = DaoFactory.createUserDao();
		List<User> _result = dao.findWhereNameEquals(name);
		for (User dto : _result) {
			display(dto);
		}
		
	}

	/**
	 * Method 'findWhereEmailEquals'
	 * 
	 * @param email
	 * @throws Exception
	 */
	public static void findWhereEmailEquals(String email) throws Exception
	{
		UserDao dao = DaoFactory.createUserDao();
		List<User> _result = dao.findWhereEmailEquals(email);
		for (User dto : _result) {
			display(dto);
		}
		
	}

	/**
	 * Method 'findWherePasswordEquals'
	 * 
	 * @param password
	 * @throws Exception
	 */
	public static void findWherePasswordEquals(String password) throws Exception
	{
		UserDao dao = DaoFactory.createUserDao();
		List<User> _result = dao.findWherePasswordEquals(password);
		for (User dto : _result) {
			display(dto);
		}
		
	}

	/**
	 * Method 'findWhereUserTypeIdEquals'
	 * 
	 * @param userTypeId
	 * @throws Exception
	 */
	public static void findWhereUserTypeIdEquals(int userTypeId) throws Exception
	{
		UserDao dao = DaoFactory.createUserDao();
		List<User> _result = dao.findWhereUserTypeIdEquals(userTypeId);
		for (User dto : _result) {
			display(dto);
		}
		
	}

	/**
	 * Method 'display'
	 * 
	 * @param dto
	 */
	public static void display(User dto)
	{
		StringBuffer buf = new StringBuffer();
		buf.append( dto.getId() );
		buf.append( ", " );
		buf.append( dto.getUsername() );
		buf.append( ", " );
		buf.append( dto.getName() );
		buf.append( ", " );
		buf.append( dto.getEmail() );
		buf.append( ", " );
		buf.append( dto.getPassword() );
		buf.append( ", " );
		buf.append( dto.getUserTypeId() );
		System.out.println( buf.toString() );
	}

}
